package com.cuit.bysj.utils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.cuit.bysj.entities.Item;

public class SelectUtils {
	public static String saveSelect(String arr, List<Item> list) {
		String sel[] = arr.split(",");

		for (int i = 0; i < sel.length; i++) {
			list.get(i).setScale(Integer.parseInt(sel[i]));
		}

		return JSON.toJSONString(list);
	}

	public static List<String> savePercent(String percentArr) {
		String per[] = percentArr.split(",");
		List<String> list = new ArrayList<>();
		for (int i = 0; i < per.length; i++) {
			list.add(i, per[i]);
		}

		return list;
	}

	//计算成绩方法
	public static double caculateScore(String arr, List<Item> list) {
		String sel[] = arr.split(",");
		double sum = 0;
		for (int i = 0; i < sel.length; i++) {
			if (sel[i].equals("1")) {
				sum = sum + 100 * list.get(i).getPercent() / 100;
			}
			if (sel[i].equals("2")) {
				sum = sum + 80 * list.get(i).getPercent() / 100;
			}
			if (sel[i].equals("3")) {
				sum = sum + 60 * list.get(i).getPercent() / 100;
			}
			if (sel[i].equals("4")) {
				sum = sum + 40 * list.get(i).getPercent() / 100;
			}
		}
		BigDecimal b = new BigDecimal(sum);
		System.out.println(b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());

		return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
	}
}
